package com.neutech.neusys.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.neutech.neusys.mapper.ConstantItemMapper;
import com.neutech.neusys.mapper.SysUserMapper;
import com.neutech.neusys.service.SysUserService;
import com.neutech.po.User;
import com.neutech.vo.ViewData;

@Service
public class SysUserServiceImpl implements SysUserService{
	@Autowired
	private SysUserMapper sysUserMapper;
	@Autowired
	private ConstantItemMapper constantMapper;
	
	//增加
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public int addNewUser(User user) {
		// TODO Auto-generated method stub
		return sysUserMapper.addNewUser(user);
	}

	//查询
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public ViewData getUser(Map<String, Object> map) {
		// TODO Auto-generated method stub
		String pageNumber = (String) map.get("pageNumber");
		try{
			Integer pn = new Integer(pageNumber);
			
			pn = pn -1;
			if(pn < 0){
				pn = 0;
			}
			pn = pn *10;
			map.put("pageNumber", pn);
		}catch(Exception e){
			map.put("pageNumber", 0);
		}
		ViewData vd = new ViewData();
		//加入数据库查询的一页数据
		vd.setMap(sysUserMapper.getUser(map));
		//加入数据库查询的总条目数
		vd.setPageNumber(sysUserMapper.getUserCount(map));;
		System.out.println(map.get("pageNumber"));
		System.out.println(map.get("DrugsName"));
		return vd;
	}

	//修改
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public User updateNewUser(User user) {
		// TODO Auto-generated method stub
		sysUserMapper.updateUser(user);
		return new User();
	}

	//删除
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public User deleteUser(User user) {
		// TODO Auto-generated method stub
		sysUserMapper.deleteUser(user);
		return new User();
	}

	//查询下拉数据
	@Override
	public List<Map<String, Object>> queryAll(String typeId) throws Exception {
		// TODO Auto-generated method stub
		List<Map<String,Object>> typeList = constantMapper.queryAll(typeId);
		return typeList;
	}

	//挂号级别列表
	@Override
	public List<Map<String,Object>> queryRegistAll(String typeID) throws Exception {
		// TODO Auto-generated method stub
		List<Map<String,Object>> regList = constantMapper.queryRegistAll(typeID);
		return regList;
	}

	//科室列表
	@Override
	public List<Map<String, Object>> queryDeptAll() throws Exception {
		// TODO Auto-generated method stub
		List<Map<String,Object>> deptList = constantMapper.queryDeptAll();				
		return deptList;
	}

}
